<template>
  <section>
    <el-select size="mini" v-model="selType" v-if="businessTypeList" @change="selTypeEvent" :disabled="disabled">
      <el-option v-for="businessType in businessTypeList" :key="businessType.id" :value="businessType.code" :label="businessType.name"/>
    </el-select>
  </section>
</template>

<script>
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import errHandler from '@/assets/errHandler.js'
  export default {
    name: "businessType",
    props:['code','disabled'],
    data() {
      return {
        businessTypeList:null,
        selType:null
      }
    },
    created() {
      // console.log(this.code)
      if(this.code) this.selType=this.code
      this.getBusinessType()
    },
    computed: {
      ...mapGetters(['department']),
    },
    watch:{
      code(nv,ov){
        if(nv) this.selType=this.code
      }
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getBusinessType(){
        this.fetch({name:"getBusinessTypeList"})
          .then(res=>{
            // console.log('业务类型列表------------',res)
            this.businessTypeList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      selTypeEvent(e){
        this.$emit('selType',e)
      }
    }
  }
</script>

<style scoped>

</style>
